﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/MainTemplate.Master" AutoEventWireup="true" CodeBehind="Download.aspx.cs" Inherits="Enterprise.Admin.Download" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <script src="../Content/Widget/AjaxFileUploader/ajaxfileupload.js" charset="utf-8" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <table id="table_list"></table>
    <div id="search_download">
        <form id="search_download_form" action="Handle/Download/GetListJson.aspx" method="get">
            <p>
                <label>名称：</label><input type="text" name="CoName" />
            </p>

            <p class="multi-language ">
                <label>语言：</label><select name="CoLanguage" class="easyui-combobox" data-options="required:true">
                    <option value="">全部</option>
                    <option value="zh_cn">简体中文</option>
                    <option value="en_us">美国英语</option>
                </select>
            </p>
        </form>
    </div>
    <div id="add_download">
        <form id="add_download_form" action="Handle/Download/Add.aspx" method="post">
            <p>
                <label>名称：</label><input type="text" name="CoName" value="" />
            </p>
            <p class="en-us disabled">
                <label>名称(En)：</label><input type="text" name="CoNameEn" value="" />
            </p>
            <p class="multi-language ">
                <label>语言：</label><select name="CoLanguage" class="easyui-combobox" data-options="required:true">
                    <option value="zh_cn">简体中文</option>
                    <option value="en_us">美国英语</option>
                </select>
            </p>
            <p>
                <label>排序：</label><input type="text" name="CoSort" value="" />
            </p>
            <p>
                <label>文件：</label><span id="add_upload_box"><input type="file" id="add_upload" name="Filedata" /></span>
            </p>
            <p>
                <label style="height: 130px; line-height: 130px;">描述：</label><textarea rows="5" cols="30" name="CoDescription"></textarea>
            </p>
            <p class="en-us disabled">
                <label style="height: 130px; line-height: 130px;">描述(En)：</label><textarea rows="5" cols="30" name="CoDescriptionEn"></textarea>
            </p>
        </form>
    </div>
    <div id="edit_download">
        <form id="edit_download_form" action="Handle/Download/Edit.aspx" method="post">
            <p>
                <label>名称：</label><input type="text" name="CoName" value="" />
                <input id="edit_download_id" name="CoDownloadId" type="hidden" value="" />
            </p>
            <p class="en-us disabled">
                <label>名称(En)：</label><input type="text" name="CoNameEn" value="" />
            </p>
            <p class="multi-language ">
                <label>语言：</label><select name="CoLanguage" class="easyui-combobox" data-options="required:true">
                    <option value="zh_cn">简体中文</option>
                    <option value="en_us">美国英语</option>
                </select>
            </p>
            <p>
                <label>排序：</label><input type="text" name="CoSort" value="" />
            </p>
            <p>
                <label style="height: 130px; line-height: 130px;">描述：</label><textarea rows="5" cols="30" name="CoDescription" id="edit_download_content"></textarea>
            </p>
            <p class="en-us disabled">
                <label style="height: 130px; line-height: 130px;">描述(En)：</label><textarea rows="5" cols="30" name="CoDescriptionEn"></textarea>
            </p>
        </form>
    </div>

    <script type="text/javascript">
        $(document).ready(function () {
            var tableList = $("#table_list").datagrid({
                title: '资源下载列表',
                fit: true,
                nowrap: true,
                autoRowHeight: false,
                striped: true,
                collapsible: true,
                url: 'Handle/Download/GetListJson.aspx',
                idField: 'id',
                singleSelect: true,
                fitColumns: true,
                onClickRow: function (rowIndex) {
                    $('#table_list').datagrid("unselectRow", rowIndex);
                },
                columns: [[
                                    { title: 'Id', field: 'id', width: 280, align: 'center', checkbox: true },
                                    { title: '名称', field: 'CoName', width: 280, align: 'center' },
                                  {
                                      title: '语言', field: 'CoLanguage', width: 100, align: 'center',
                                      formatter: function (value) {
                                          var text;
                                          $.each(languageData, function () {
                                              if (this.id == value) {
                                                  text = this.text;
                                                  return false;
                                              }
                                              return true;
                                          });
                                          return text;
                                      }
                                  },
                                    { title: '排序', field: 'CoSort', width: 100, align: 'center' },
                                 {
                                     title: '下载', field: 'OpDown', width: 80, align: 'center', formatter: function (value, rec) {
                                         return '<a href="Handle/Download/DownFile.aspx?id=' + rec.id + '" mce_href="#" >下载</a> ';
                                     }
                                 },
                                  {
                                      title: '修改', field: 'OpEdit', width: 80, align: 'center', formatter: function (value, rec) {
                                          return '<a href="javascript:void(0);" mce_href="#" onclick="edit(\'' + rec.id + '\')">修改</a> ';
                                      }
                                  },
                                   {
                                       title: '删除', field: 'OpDelete', width: 80, align: 'center', formatter: function (value, rec) {
                                           return '<a href="javascript:void(0);" mce_href="#" onclick="del(\'' + rec.id + '\')">删除</a> ';

                                       }
                                   }
                ]],
                pagination: true,
                rownumbers: true,
                toolbar: [{
                    text: '添加',
                    iconCls: 'icon-add',
                    handler: function () {
                        add();
                    }
                }, {
                    text: '修改',
                    iconCls: 'icon-edit',
                    handler: function () {
                        var selectData = $('#table_list').datagrid('getSelected');
                        if (selectData == null) {
                            $.messager.show({
                                title: '提示',
                                msg: '请选择要修改记录！',
                                timeout: 5000,
                                showType: 'fade'
                            });
                        } else {
                            edit(selectData.id);
                        }
                    }

                }, {
                    text: '删除',
                    iconCls: 'icon-remove',
                    handler: function () {
                        var selectData = $('#table_list').datagrid('getSelected');
                        if (selectData == null) {
                            $.messager.show({
                                title: '提示',
                                msg: '请选择要删除记录！',
                                timeout: 5000,
                                showType: 'fade'
                            });
                        } else {
                            del(selectData.id);
                        }

                    }

                }, {
                    text: '查找',
                    iconCls: 'icon-search',
                    handler: function () {
                        $('#search_download').dialog("open");
                    }

                }]
            });
            $('#add_download').dialog({
                title: '添加资源',
                width: 600,
                height: 500,
                closed: true,
                buttons: [{
                    text: '保存',
                    iconCls: 'icon-ok',
                    handler: function () {
                        addSave(function () { });
                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $('#add_download').dialog('close');
                    }
                }]

            });
            $('#edit_download').dialog({
                title: '修改资源',

                width: 600,
                height: 500,
                closed: true,
                buttons: [{
                    text: '保存',
                    iconCls: 'icon-ok',
                    handler: function () {
                        editSave();
                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $('#edit_download').dialog('close');
                    }
                }]
            });
            $('#search_download').dialog({
                title: '检索资源',
                width: 400,
                height: 250,
                closed: true,
                buttons: [{
                    text: '查找',
                    iconCls: 'icon-ok',
                    handler: function () {
                        tableList.datagrid("reload", $('#search_download_form').serializeObject());
                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $('#search_download').dialog('close');
                    }
                }]
            });
            $('#edit_download_form').form({
                onBeforeLoad: function () {
                },
                onLoadSuccess: function () {
                    $('#edit_download').dialog("open");
                },
                onLoadError: function () {
                }
            });
        });
        //获取资源详细
        function edit(id) {
            $('#edit_download_form').form('load', 'Handle/Download/GetDetailJson.aspx?id=' + id);
        }
        function del(id) {
            $.messager.confirm("提示", "确认删除?", function (b) {
                if (b) {
                    $.ajax({
                        type: "POST",
                        url: "Handle/Download/Delete.aspx",
                        data: { id: id },
                        success: function (msg) {
                            $.messager.show({
                                title: '提示',
                                msg: msg.message,
                                timeout: 5000,
                                showType: 'fade'
                            });
                            if (msg.state)
                                $("#table_list").datagrid("reload");
                        },
                        error: function () {
                            $.messager.show({
                                title: '提示',
                                msg: '删除失败！',
                                timeout: 5000,
                                showType: 'fade'
                            });
                        }
                    });
                }
            });
        }
        function add() {
            $('#add_download').dialog("open");
        }
        //添加保存
        function addSave() {
            $.ajaxFileUpload({
                type: "POST",
                fileElementId: 'add_upload',
                dataType: 'json',
                url: "Handle/Download/Add.aspx",
                data: $('#add_download_form').serializeObject(),
                success: function (msg) {
                    $.messager.show({
                        title: '提示',
                        msg: msg.message,
                        timeout: 5000,
                        showType: 'fade'
                    });
                    if (msg.state) {
                        $('#add_download_form')[0].reset();
                        $("#table_list").datagrid("reload");
                    }
                },
                error: function () {
                    $.messager.show({
                        title: '提示',
                        msg: '保存失败！',
                        timeout: 5000,
                        showType: 'fade'
                    });
                }
            });
        }
        //编辑保存
        function editSave() {
            $.ajax({
                type: "POST",
                url: "Handle/Download/Edit.aspx",
                data: $('#edit_download_form').serialize(),
                success: function (msg) {
                    $.messager.show({
                        title: '提示',
                        msg: msg.message,
                        timeout: 5000,
                        showType: 'fade'
                    });
                    if (msg.state) {
                        $("#table_list").datagrid("reload");
                    }
                },
                error: function () {
                    $.messager.show({
                        title: '提示',
                        msg: '保存失败！',
                        timeout: 5000,
                        showType: 'fade'
                    });
                }
            });
        }
    </script>
</asp:Content>
